home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fscmd / fscmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-07  |  8.8 KB  |  280 lines

  1. /* 
  2.  * fscmd.c --
  3.  *
  4.  *    Command-line interface to the Fs_Command system call.
  5.  *    This is used to set various filesystem parameters, ie.
  6.  *    min/max cache size, cache write-back, debug printing.
  7.  *
  8.  * Copyright (C) 1986 Regents of the University of California
  9.  * All rights reserved.
  10.  */
  11.  
  12. #ifndef lint
  13. static char rcsid[] = "$Header: /sprite/src/cmds/fscmd/RCS/fscmd.c,v 1.20 90/02/16 11:26:37 brent Exp Locker: shirriff $ SPRITE (Berkeley)";
  14. #endif not lint
  15.  
  16. #include "sprite.h"
  17. #include "status.h"
  18. #include "option.h"
  19. #include "fs.h"
  20. #include "fsCmd.h"
  21. #include "stdio.h"
  22. /*
  23.  * Command line options.
  24.  */
  25.  
  26. int minBlocks = -1;
  27. int maxBlocks = -1;
  28. int    cacheWriteBack = -1;
  29. Boolean    flushCache = FALSE;
  30. int    fsTracing = -1;
  31. int    cacheDebug = -1;
  32. int    migDebug = -1;
  33. int    nameCaching = -1;
  34. int    clientCaching = -1;
  35. int    contextSwitches = -1;
  36. int    noStickySegs = -1;
  37. int    numCleanerProcs = -1;
  38. int    readAhead = -1;
  39. int    readAheadTracing = -1;
  40. int    writeThrough = -1;
  41. int    writeBackOnClose = -1;
  42. int    delayTmpFiles = -1;
  43. int    tmpDirNum = -1;
  44. int    writeBackASAP = -1;
  45. int    wbOnLastDirtyBlock = -1;
  46. int    writeBackInterval = -1;
  47. int    blockSkew = -1;
  48. int    largeFileMode = -1;
  49. int    maxFilePortion = -1;
  50. int    deleteHistograms = -1;
  51. Boolean zeroStats = FALSE;
  52. int     generic = -1;
  53. char    *updateSummary = NULL;
  54.  
  55. Option optionArray[] = {
  56.     {OPT_INT, "B", (Address) &blockSkew, "\tSet block gap for allocation."},
  57.     {OPT_INT, "C", (Address) &clientCaching, "\tSet client caching flag."},
  58.     {OPT_INT, "D", (Address) &cacheDebug, "\tSet cache debug flag."},
  59.     {OPT_INT, "H", (Address)&deleteHistograms, "\tSet delete histograms flag."},
  60.     {OPT_INT, "L", (Address)&maxFilePortion, "\tSet large file portion."},
  61.     {OPT_INT, "M", (Address) &maxBlocks, "\tMaximum number of blocks allowed in file system cache."},
  62.     {OPT_INT, "N", (Address) &nameCaching, "\tSet name caching flag."},
  63.     {OPT_TRUE, "O", (Address)&zeroStats, "\tZero fsStat counters."},
  64.     {OPT_INT, "R", (Address) &readAheadTracing, "\tSet read ahead tracing flag."},
  65.     {OPT_INT, "S", (Address) &writeBackInterval, "\tSet cache write back interval."},
  66.     {OPT_INT, "W", (Address) &writeBackOnClose, "\tSet write-back-on-close flag"},
  67.     {OPT_INT, "X", (Address) &tmpDirNum, "\tSet tmp directory number."},
  68.     {OPT_INT, "Z", (Address) &contextSwitches, "\tDo context switches."},
  69.     {OPT_INT, "b", (Address) &numCleanerProcs, "\tSet the maximum number of block cleaner processes."},
  70.     {OPT_TRUE, "f", (Address) &flushCache, "\tFlush and invalidate cache."},
  71.     {OPT_INT, "g", (Address) &migDebug, "\tSet migration debug flag."},
  72.     {OPT_INT, "l", (Address)&largeFileMode, "\tSet large file mode for cache."},
  73.     {OPT_INT, "m", (Address) &minBlocks, "\tMinimum number of blocks allowed in file system cache."},
  74.     {OPT_INT, "r", (Address) &readAhead, "\tSet number of blocks of read ahead."},
  75.     {OPT_INT, "s", (Address) &cacheWriteBack, "\tSet cache write back flag."},
  76.     {OPT_INT, "t", (Address) &fsTracing, "\tSet fs tracing value."},
  77.     {OPT_STRING, "u", (Address)&updateSummary, "\tUpdate summary info from disk."},
  78.     {OPT_INT, "v", (Address) &noStickySegs, "\tSet no sticky segments flag."},
  79.     {OPT_INT, "w", (Address) &writeThrough, "\tSet write through flag."},
  80.     {OPT_INT, "x", (Address) &delayTmpFiles, "\tSet delay tmp files flag."},
  81.     {OPT_INT, "y", (Address) &writeBackASAP, "\tSet write back ASAP flag."},
  82.     {OPT_INT, "z", (Address) &wbOnLastDirtyBlock, "\tSet write back on last dirty block flag."},
  83.     {OPT_INT, "generic", (Address) &generic, "\tGeneric file system hook."},
  84. };
  85. int numOptions = sizeof(optionArray) / sizeof(Option);
  86.  
  87.  
  88. /*
  89.  *----------------------------------------------------------------------
  90.  *
  91.  * main --
  92.  *
  93.  *    Collects arguments and branch to the code for the fs command.
  94.  *
  95.  * Results:
  96.  *    None.
  97.  *
  98.  * Side effects:
  99.  *    Calls Fs_Command...
  100.  *
  101.  *----------------------------------------------------------------------
  102.  */
  103. main(argc, argv)
  104.     int argc;
  105.     char *argv[];
  106. {
  107.     register ReturnStatus status = SUCCESS;    /* status of system calls */
  108.  
  109.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  110.  
  111.     if (minBlocks != -1) {
  112.     (void) Fs_Command(FS_RAISE_MIN_CACHE_SIZE, sizeof(int), &minBlocks);
  113.     }
  114.     if (maxBlocks != -1) {
  115.     (void) Fs_Command(FS_LOWER_MAX_CACHE_SIZE, sizeof(int), &maxBlocks);
  116.     }
  117.     if (flushCache) {
  118.     /*
  119.      * Flush the filesystem cache.
  120.      */
  121.     int numLockedBlocks;
  122.     status = Fs_Command(FS_EMPTY_CACHE, sizeof(int),
  123.                         (Address) &numLockedBlocks);
  124.     if (numLockedBlocks > 0) {
  125.         fprintf(stderr, "%d locked blocks left\n",
  126.                       numLockedBlocks);
  127.     }
  128.     }
  129.     if (zeroStats) {
  130.     /*
  131.      * Zero out the file system statistics.
  132.      */
  133.     (void) Fs_Command(FS_ZERO_STATS, 0, (Address) NULL);
  134.     }
  135.     if (updateSummary != NULL) {
  136.     /*
  137.      * Reread summary information from disk and update in-memory copy.
  138.      */
  139.     status = Fs_Command(FS_REREAD_SUMMARY_INFO, strlen(updateSummary)+1,
  140.             updateSummary);
  141.     }
  142.     if (writeBackInterval != -1) {
  143.     int    newInterval;
  144.  
  145.     newInterval = writeBackInterval;
  146.     Fs_Command(FS_SET_WRITE_BACK_INTERVAL, sizeof(int),
  147.            &writeBackInterval);
  148.     printf("Cache write back interval was %d, now %d\n",
  149.         writeBackInterval, newInterval);
  150.     }
  151.     /*
  152.      * Set various file system flags.  The Fs_Command system call returns
  153.      * the old value of the flag in place of the value passed in.
  154.      */
  155.     if (cacheWriteBack != -1) {
  156.     /*
  157.      * Set the cache write-back flag.
  158.      */
  159.     status = SetFlag(FS_DISABLE_FLUSH, cacheWriteBack, "Cache write-back");
  160.     }
  161.     if (fsTracing != -1) {
  162.     SetFlag(FS_SET_TRACING, fsTracing, "Filesystem tracing");
  163.     }
  164.     if (cacheDebug != -1) {
  165.     status = SetFlag(FS_SET_CACHE_DEBUG, cacheDebug, "Cache debug prints");
  166.     }
  167.     if (migDebug != -1) {
  168.     status = SetFlag(FS_SET_MIG_DEBUG, migDebug, "Migration debug prints");
  169.     }
  170.     if (nameCaching != -1) {
  171.     status = SetFlag(FS_SET_NAME_CACHING, nameCaching, "Name caching");
  172.     }
  173.     if (clientCaching != -1) {
  174.     status = SetFlag(FS_SET_CLIENT_CACHING, clientCaching, "Client caching");
  175.     }
  176.     if (noStickySegs != -1) {
  177.     status = SetFlag(FS_SET_NO_STICKY_SEGS, noStickySegs, 
  178.              "No sticky segments");
  179.     }
  180.  
  181.     if (contextSwitches != -1) {
  182.     status = Fs_Command(FS_TEST_CS, 4, (Address) &contextSwitches);
  183.     }
  184.     if (numCleanerProcs != -1) {
  185.     status = SetInt(FS_SET_CLEANER_PROCS, numCleanerProcs,
  186.             "Num block cleaner procs");
  187.     }
  188.     if (readAhead != -1){
  189.     status = SetInt(FS_SET_READ_AHEAD, readAhead,
  190.             "Num blocks of read ahead");
  191.     }
  192.     if (readAheadTracing != -1) {
  193.     status = SetFlag(FS_SET_RA_TRACING, readAheadTracing, 
  194.             "Read ahead tracing");
  195.     }
  196.     if (writeThrough != -1) {
  197.     status = SetFlag(FS_SET_WRITE_THROUGH, writeThrough, "Write through");
  198.     }
  199.     if (writeBackOnClose != -1) {
  200.     status = SetFlag(FS_SET_WRITE_BACK_ON_CLOSE, writeBackOnClose,
  201.         "Write-back-on-close");
  202.     }
  203.     if (delayTmpFiles != -1) {
  204.     status = SetFlag(FS_SET_DELAY_TMP_FILES, delayTmpFiles,
  205.              "Delay tmp files");
  206.     }
  207.     if (tmpDirNum != -1) {
  208.     status = Fs_Command(FS_SET_TMP_DIR_NUM, sizeof(int), &tmpDirNum);
  209.     }
  210.     if (writeBackASAP != -1) {
  211.     status = SetFlag(FS_SET_WRITE_BACK_ASAP, writeBackASAP,
  212.              "Write back ASAP");
  213.     }
  214.     if (wbOnLastDirtyBlock != -1) {
  215.     status = SetFlag(FS_SET_WB_ON_LAST_DIRTY_BLOCK, wbOnLastDirtyBlock,
  216.              "Write back on last dirty block");
  217.     }
  218.     if (blockSkew != -1) {
  219.     status = SetInt(FS_SET_BLOCK_SKEW, blockSkew,
  220.              "Block gap for allocation");
  221.     }
  222.     if (largeFileMode != -1) {
  223.     status = SetFlag(FS_SET_LARGE_FILE_MODE, largeFileMode,
  224.              "Large file mode for cache");
  225.     }
  226.     if (maxFilePortion != -1) {
  227.     status = SetFlag(FS_SET_MAX_FILE_PORTION, maxFilePortion,
  228.              "Maximum large file portion for cache");
  229.     }
  230.     if (deleteHistograms != -1) {
  231.     status = SetFlag(FS_SET_DELETE_HISTOGRAMS, deleteHistograms,
  232.              "Keep histograms of size/age distributions on delete");
  233.     }
  234.     if (generic != -1) {
  235.     status = SetFlag(FS_GENERIC_COMMAND, generic,
  236.              "Generic hook into the file system");
  237.     }
  238.     exit(status);
  239. }
  240.  
  241. ReturnStatus
  242. SetInt(command, value, comment)
  243.     int command;        /* Argument to Fs_Command */
  244.     int value;            /* Value for int */
  245.     char *comment;        /* For Io_Print */
  246. {
  247.     register int newValue;
  248.     register ReturnStatus status;
  249.  
  250.     newValue = value;
  251.     status = Fs_Command(command, sizeof(int), (Address) &value);
  252.     if (status != SUCCESS) {
  253.     printf("%s failed <%x>\n", comment, status);
  254.     } else {
  255.     printf("%s %d, was %d\n", comment, newValue, value);
  256.     }
  257.     return(status);
  258. }
  259.  
  260. ReturnStatus
  261. SetFlag(command, value, comment)
  262.     int command;        /* Argument to Fs_Command */
  263.     int value;            /* Value for flag */
  264.     char *comment;        /* For Io_Print */
  265. {
  266.     register int newValue;
  267.     register ReturnStatus status;
  268.  
  269.     newValue = value;
  270.     status = Fs_Command(command, sizeof(int), (Address) &value);
  271.     if (status != SUCCESS) {
  272.     printf("%s failed <%x>\n", comment, status);
  273.     } else {
  274.     printf("%s %s, was %s\n", comment,
  275.              newValue ? "on" : "off",
  276.              value ? "on" : "off");
  277.     }
  278.     return(status);
  279. }
  280.